/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: asus
 * Date: 2025-01-03
 * Time: 12:36
 */
public class LengthOfLastWord {
    public int lengthOfLastWord(String s) {
        int index = s.length() - 1;
        boolean flag = false;
        int ret = 0;
        while (index >= 0) {
            if (s.charAt(index) == ' ' && flag) {
                return ret;
            } else if (s.charAt(index) != ' '){
                ret++;
                flag = true;
            }
            index--;
        }
        return ret;
    }
}
